<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        ul{
            display: flex;
        }
        li{
            background-color: aqua;
            color: red;
            padding: 10px 15px;
        }
        li.action{
            background-color: red;
            color: aqua;
        }
        .box{
            position: relative;
        }
        .box > div{
            height: 300px;
            border: 1px solid #000;
            display: none;
        }
        .box > div.action{
            display: block;
        }
    </style>
</head>
<body>
    <ul>
        <li class="action">标题1</li>
        <li>标题2</li>
        <li>标题3</li>
        <li>标题4</li>
    </ul>
    <div class="box">
        <div class="action">内容1111</div>
        <div>内容2222</div>
        <div>内容3333</div>
        <div>内容4444</div>
    </div>
    <script>
        var lis = document.querySelectorAll('li');
        var boxs = document.querySelectorAll('.box>div');
        for (let i = 0; i < lis.length; i++) {
            lis[i].setAttribute('index', i);
            lis[i].onclick = function (){
                for (var i = 0; i < lis.length; i++) {
                    lis[i].className = '';
                }
                this.className = 'action';
                var index = this.getAttribute('index');
                console.log(index);
                for (var i = 0; i < boxs.length; i++) {
                    boxs[i].style.display = 'none';                    
                }
            boxs[index].style.display = 'block';
        }
        }
    </script>                                                                                             
</body>
</html>